//
//  ViewController.m
//  gggggPro
//
//  Created by EDZ on 2017/11/9.
//  Copyright © 2017年 EDZ. All rights reserved.
//

#import "ViewController.h"
#import "YLSecondViewController.h"
#import "SubController.h"
#import "UIViewController+tool.h"
#import <WebKit/WebKit.h>
//适配布局常用内联函数和宏
//状态栏高度
NS_INLINE CGFloat Status_Bar_Height(){
    if (@available(iOS 11.0,*)) {
        UIWindow *mainView = [UIApplication sharedApplication].keyWindow;
        return mainView.safeAreaInsets.top;
    }else{
        return 20.0f;
    }
}

//导航栏高度
#define Navigation_Bar_Height 44.0f

//状态栏+导航栏高度
NS_INLINE CGFloat Status_And_Navigation_Height(){
    return Status_Bar_Height() + Navigation_Bar_Height;
}

//TabBar高度
#define TabBar_Height 49.0f

//底部安全区域高度34.0f
NS_INLINE CGFloat Bottom_Safe_Height(){
    if (@available(iOS 11.0,*)) {
        UIWindow *mainView = [UIApplication sharedApplication].keyWindow;
        return mainView.safeAreaInsets.bottom;
    }else{
        return 0.0f;
    }
}

//TabBar+安全区域高度
NS_INLINE CGFloat TabBar_And_Bottom_Safe_Height(){
    return Bottom_Safe_Height() + TabBar_Height;
}

@interface ViewController ()
@property (strong, nonatomic) UIView *redview;
@property (nonatomic ,strong) UIScrollView *scroll;
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //回滚--1
    
//    CGFloat gg = Status_And_Navigation_Height();
//
//    self.navigationController.navigationBar.tintColor = [UIColor clearColor];
//    UIImage *image = [UIViewController createAImageWithColor:[UIColor clearColor] alpha:1];
//    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
//
//    UIView *rightNav = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
//    rightNav.backgroundColor = [UIColor cyanColor];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightNav];
//
    
    //我是主分支。我要合并
        
}

- (void)buttonClick:(UIButton *)sender {
    //master add
    
//1、这个方式的文件太大了保存的时候 36-237
    UIImage *image = [UIImage imageNamed:@"2222"];
   NSData *imageData =  UIImageJPEGRepresentation(image, 1);
    
    // 2、 36-40
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"3333" ofType:@"png"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    NSString *root = @"/Users/guyilin/Desktop";
    root = [root stringByAppendingPathComponent:@"444.png"];
    
    [imageData writeToFile:root atomically:YES];
    NSLog(@"=====");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // master add
//    self.edgesForExtendedLayout = UIRectEdgeNone;//all是默认
    
    /**********************在ios14出现导航的push问题都是UIRectEdgeNone的锅，让subview从导航下开始******/
    
//    self.navigationController.navigationBar.translucent = NO;//yes是默认
    self.title = @"首页";
    self.view.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:self.scroll];
//
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 100, 100, 100);
    button.backgroundColor = [UIColor redColor];
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    if (@available(iOS 11.0, *)) {
        NSLog(@"我是ios11");
    }
   
    

    

//    WKWebView *webview = [[WKWebView alloc] initWithFrame:CGRectMake(120, 0, 200, 300)];
//    webview.backgroundColor = [UIColor whiteColor];
//    webview.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//    [self.view addSubview:webview];
//    // 百度的连接处理了 当web是在导航 ⬆️就开始的情况
//    NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];
//    NSURLRequest *request = [NSURLRequest requestWithURL:url];
//    [webview loadRequest:request];
//
  
//    [self test_layer];

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    SubController *vc = [[SubController alloc]initWith:@"123"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (UIScrollView *)scroll {
    if (!_scroll) {
        _scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        _scroll.backgroundColor = [UIColor lightGrayColor];
        _scroll.contentSize = CGSizeMake(0, self.view.frame.size.height * 2);
    }
    return  _scroll;;
}


// cagrandientlayer不是画线。没有相应的属性 只能addlayer。不能setmask
- (void)test_layer {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 300, 300)];
    view.backgroundColor = [UIColor yellowColor];
//    view.layer.backgroundColor = [UIColor yellowColor].CGColor;
    [self.view addSubview:view];
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:view.frame];
    CGFloat top = 24;

    [path appendPath:[[UIBezierPath bezierPathWithRoundedRect: CGRectMake(412 - 80 - 40-150, top + 24+188, 80, 40) cornerRadius:20] bezierPathByReversingPath]];
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    
    //1 挖空
//    shapeLayer.frame = view.bounds;
    shapeLayer.fillColor = [UIColor whiteColor].CGColor;// 画龙点睛之笔（内外均是透明）--- 如果不是透明 就等于挖空一块path
    shapeLayer.strokeColor = [UIColor redColor].CGColor;// 笔画的地方不透明
//    shapeLayer.lineCap = kCALineCapRound;//指定线的边缘是圆的
    shapeLayer.lineWidth = 10;
//    shapeLayer.opacity = 1; //背景颜色的透明度
    shapeLayer.path = path.CGPath;
    // 满足以上4个条件即可看到mask
   
    
    // 图层留着
//    shapeLayer.frame = view.bounds;
//    shapeLayer.fillColor = [[UIColor clearColor] CGColor];  //填充色为无色
//    shapeLayer.strokeColor = [[UIColor redColor] CGColor]; //指定path的渲染颜色,这里可以设置任意不透明颜色
//    shapeLayer.opacity = 1; //背景颜色的透明度
//    shapeLayer.lineCap = kCALineCapRound;//指定线的边缘是圆的
//    shapeLayer.lineWidth = 10;//线的宽度
//    shapeLayer.path =[path CGPath];
    
    
    // 挖角
//    UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(100, 100)];
//    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
//    [shape setPath:rounded.CGPath];
//    view.layer.mask = shape;
    
    // 不同的性质 uibezierpath用法不一样
    

    
    self.gradientLayer = [CAGradientLayer layer];
      self.gradientLayer.frame = view.bounds;
      //laye的position和view的center一样 居中属性
      self.gradientLayer.position = CGPointMake(150, 150);//(150,238)是view的center
      //边宽
      self.gradientLayer.borderWidth = 1.f;
    [view.layer addSublayer:self.gradientLayer];

      //设置颜色
      self.gradientLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,
                                    (__bridge id)[UIColor greenColor].CGColor,
                                    (__bridge id)[UIColor blueColor].CGColor];
      
      //设置颜色渐变方向 (0,0)->(1,1)则45度方向 (0,0)->(1,0)上->下
      self.gradientLayer.startPoint = CGPointMake(0, 0);
      self.gradientLayer.endPoint = CGPointMake(0, 1);
      
      //设置颜色分割点
      self.gradientLayer.locations = @[@(0.25),@(0.5),@(0.75)];
    
//        [view.layer setMask:shapeLayer];
}

@end

@implementation UIButton (ENUIKit_EnlargeClickEdge)

//- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
//    // 管他十万八千里 都能点击到 不用hit-test
//    return YES;
//}
@end
